//package com.game.manager.service;
//
//import com.game.manager.common.GmConstants;
//import com.game.manager.common.GmDateUtils;
//import com.game.manager.dao.GmAccountRepository;
//import com.game.manager.dao.entity.GmAccount;
//import lombok.AllArgsConstructor;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Component;
//import org.springframework.util.CollectionUtils;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Optional;
//
//@Component
//@AllArgsConstructor
//public class UserDetailsServiceImpl implements UserDetailsService {
//    private GmAccountRepository accountRepository;
//
//    @Override
//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        Optional<GmAccount> accountOptional = Optional.ofNullable(accountRepository.findByUsername(username));
//        //从数据库获取账户信息
//        GmAccount gmAccount = accountOptional.get();
//        if((gmAccount == null)&&(username.equals(GmConstants.ADMIN))) {
//            gmAccount = new GmAccount();
//            List<String> roles = new ArrayList<>();
//            roles.add("73e95060f3234011ad04f2c551342cac");
//            gmAccount.setCreateTime(GmDateUtils.yyyyMMddHHmmss());
//            gmAccount.setCreator(username);
//            gmAccount.setUsername(username);
//            gmAccount.setPassword("111111");
//            gmAccount.setRoles(roles);
//            accountRepository.insert(gmAccount);
//        }
//        List<SimpleGrantedAuthority> authorityList = new ArrayList<>();
//        if(!CollectionUtils.isEmpty(gmAccount.getRoles())){
//            for(String role : gmAccount.getRoles()){
//                authorityList.add(new SimpleGrantedAuthority(role));
//            }
//        }
//        return new User(
//                gmAccount.getUsername(),
//                gmAccount.getPassword(),
//                authorityList
//        );
//    }
//}
